/**
 * 后端处理, 抽取对象模型
 * */
 setCmd("fetchModuleInfo", {->
    def args = join($app.projects, ',', {x -> "'$x'"});
    def rows = select("""select m.id, v.project,v.ns,v.module as `name`, v.module as `code`,v.title , 1 is_enabled from (
         select project as project,ns,module,max(title) title from sys_view where project in (${args})
         group by project,ns, module) as v
      left join sys_modules m on v.project = m.project and v.ns = m.ns and v.module = m.name 
      where m.id is null; """);
      rows.forEach({x -> 
         x.id = newId();
      });
   println "新增对象数据：${rows.size()} 条！";
   def insCmd = """insert into sys_modules (id,project,ns,`name`,`code`, title,is_enabled) 
      values(#{id},#{project},#{ns},#{name},#{code}, #{title},#{is_enabled});""";
   dbExecute(insCmd, rows);

   fetchModuleMethods(args);
 });

 def fetchModuleMethods(args) {
   def rows = select("""select * from (
      select method.id, m.id module_id, b.method as `code`,b.method as `name`,b.title, 'object' input,'object' output,b.note from sys_view v 
         inner join sys_view_buttons b on v.id = b.view_id
         inner join sys_modules m on m.project = v.project and m.ns = v.ns and m.`name` = v.module
         left join sys_module_methods method on m.id = method.module_id and method.`name` = b.method
      where v.project in(${args}) and b.method is not null and method.id is null) as t;""");
   rows.forEach({x -> 
      x.id = newId();
   });
   println "新增方法数据：${rows.size()} 条！";
   def insCmd = """insert into sys_module_methods (id, module_id, code, name, title, input, output, note) 
    values (#{id}, #{module_id}, #{code}, #{name}, #{title}, #{input}, #{output}, #{note});""";
   dbExecute(insCmd, rows);
 }